/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.wechatuser.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.sql.Insert;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;

/**
* @website https://el-admin.vip
* @description /
* @author maojinhui
* @date 2020-08-21
**/
@Entity
@Getter
@Setter
@Table(name="wechat_user")
public class WechatUser extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "id")
    private Long id;

    @Column(name = "open_id",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "用户openid")
    private String openId;

    @Column(name = "session_key",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "小程序session_key")
    @JsonIgnore
    private String sessionKey;

    @Column(name = "unionid")
    @ApiModelProperty(value = "多应用间用户唯一id")
    private String unionid;

    @Column(name = "nick_name")
    @ApiModelProperty(value = "用户昵称")
    private String nickName;

    @Column(name = "gender")
    @ApiModelProperty(value = "用户性别")
    private Integer gender;

    @Column(name = "language")
    @ApiModelProperty(value = "用户语言")
    private String language;

    @Column(name = "city")
    @ApiModelProperty(value = "城市")
    private String city;

    @Column(name = "province")
    @ApiModelProperty(value = "省")
    private String province;

    @Column(name = "country")
    @ApiModelProperty(value = "国家")
    private String country;

    @Column(name = "avatar_url")
    @ApiModelProperty(value = "头像")
    private String avatarurl;


    @Column(name = "user_id")
    @NotNull(groups = Update.class)
    @GenericGenerator(name = "idGenerator" , strategy = "uuid")
    @GeneratedValue(generator="idGenerator")
    @ApiModelProperty(value = "生成的用户的id")
    private String userId;

    @Column(name = "phone")
    @ApiModelProperty(value = "用户绑定手机号")
    private String phone;


    public void copy(WechatUser source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}